﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;
using OpenAdmin.Core.Enums;

namespace OpenAdmin.Core.Models;

/// <summary>
/// 用户表
/// </summary>
[Table("SysUser")]
public class SysUser : TenantEntityBase<ApplicationDbContextLocator>, IEntityTypeConfigure<SysUser>
{
    /// <summary>
    /// 用户名
    /// </summary>
    public string UserName { get; set; }
    /// <summary>
    /// 密码 
    /// </summary>
    public string Password { get; set; }
    /// <summary>
    /// 用户真实姓名
    /// </summary>
    public string RealName { get; set; }
    /// <summary>
    /// 头像
    /// </summary>
    public string Avatar { get; set; }
    /// <summary>
    /// 用户状态
    /// </summary>
    public int Status { get; set; }
    /// <summary>
    /// 用户类型
    /// </summary>
    public UserType UserType { get; set; }
    /// <summary>
    ///最后登录时间 
    /// </summary>
    public DateTimeOffset? LastLoginTime { get; set; }
    /// <summary>
    /// 性别
    /// </summary>
    public int Gender { get; set; }
    /// <summary>
    /// 年龄
    /// </summary>
    public int Age { get; set; }
    /// <summary>
    /// 生日
    /// </summary>
    public DateTimeOffset? Birthday { get; set; }

    public void Configure(EntityTypeBuilder<SysUser> entityBuilder)
    {
        entityBuilder.Property(p => p.UserName).HasMaxLength(50).IsRequired();
        entityBuilder.Property(p => p.Password).HasMaxLength(50).IsRequired();
        entityBuilder.Property(p => p.RealName).HasMaxLength(50).IsRequired();
        entityBuilder.Property(p => p.Avatar).HasMaxLength(100);
    }
}
